package com.service.impl;

import com.dao.UserDao;
import com.pojo.User;
import com.service.UserService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserDao userDao;

    public User getUserOne(int id) {
        User user = userDao.getUserById(id);
        return user;
    }

    @Transactional
    public boolean addUser(User user) {
        int i = userDao.insertUser(user);
        try {
            if(i>0){
                int num=1/0;
                return false;
            }
        }catch (Exception e){
           throw  new RuntimeException("事物已经回滚..");
        }
        return true;
    }
}
